//package com.ahm.consumer.service.OrderServiceImpl;
//
//import com.ahm.consumer.pojo.Order;
//import com.ahm.consumer.pojo.Product;
//import com.ahm.consumer.service.OrderService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
//import org.springframework.core.ParameterizedTypeReference;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Service;
//import org.springframework.util.CollectionUtils;
//import org.springframework.web.client.RestTemplate;
//
//import javax.annotation.Resource;
//import java.util.List;
//
///**
// * @author anhaimeng
// * @title: OrderServiceImpl
// * @projectName eurekademo002
// * @description: TODO
// * @date 2021/10/199:16
// */
///*功能描述
// * @author ahm
// */
//@Service
//public class OrderServiceImpl2 implements OrderService {
//
//    @Autowired
//    private RestTemplate restTemplate;
//
//
//    @Autowired
//    private LoadBalancerClient loadBalancerClient; // Ribbon 负载均衡器
//
//
//    @Resource
//    private DiscoveryClient discoveryClient;
//
//    @Override
//    public Order selectOrderById(Integer id) {
//        return new Order(id, "order-001", "中国", 31994D, selectProductListByLoadBalancerClient());
//    }
//
//    private List<Product> selectProductListByLoadBalancerClient(){
//
//         // 根据服务名称获取服务实例
//          // 获取主机 端口 拼字字符串
//         //restTemplate.exchange 方法发送请求 返回 ResponseEntity 第四个参数为响应的内容
//
//        ServiceInstance choose = loadBalancerClient.choose("service-provider");
//        // 拼接请求
//        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("http://"+choose.getHost()+":"+choose.getPort()+"/product/list");
//        ResponseEntity<List<Product>> exchange = restTemplate.exchange(stringBuilder.toString(), HttpMethod.GET, null, new ParameterizedTypeReference<List<Product>>() {
//        });
//        return exchange.getBody();
//
//    }
//
//
//
//
//
//}
